<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <title>工单滞留报表</title>
    <link rel="stylesheet" type="text/css" href="./css/main.css" />
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="./css/layuiAdminTheme.css" />
    <style type="text/css">
        .layui-form-label {
            width: auto !important;
        }

        .createTime,
        .operation span:first-of-type {
            color: #1990FF;
        }

        .operation span:last-of-type {
            color: #F5222D;
        }

        .pageNav {
            margin: 0 auto;
            width: fit-content;
        }

        .pageNav a,
        .operation span {
            cursor: pointer;
            display: inline-block;
        }

        .operation{
            overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
        }

        cite {
            cursor: default;
        }

        td
        {
            white-space: nowrap;
            text-align: center;
            vertical-align:middle;
        }



    </style>
</head>
<body>
<script src="./js/main.js" charset="utf-8"></script>
<!--    <script src="https://cdn.jsdelivr.net/npm/jquery" charset="utf-8"></script>-->
<!--    <script src="https://www.layuicdn.com/layui/layui.js" charset="utf-8"></script>-->
<script src="./layui/layui.js" charset="utf-8"></script>
<script src="./js/jQuery.main.js"></script>
<script src="./js/jquery-migrate-1.2.1.js"></script>
<script src="./js/xm-select.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/jquery.jqprint-0.3.js" type="text/javascript" charset="utf-8"></script>

<form class="layui-form" action="" lay-filter="data">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">搜索：</label>
            <input type="text" name="orderNum" id="orderNum" class="layui-input" style="width: 12em;" placeholder="工单编号或父级LotNo" value="">
        </div>
        <div class="layui-inline">
            <!--          <input id="deptName" type="text" name="orderDept" class="layui-input" style="width: 8em;" placeholder="所属部门" value="" >-->
            <select id="deptName" type="text" name="orderDept" class="layui-input" style="width: 8em;" lay-filter="orderDept" onclick="isAdminOfOrder()">
            </select>
        </div>
        <div class="layui-inline">
            <!--          <input id="deptName" type="text" name="orderDept" class="layui-input" style="width: 8em;" placeholder="所属部门" value="" >-->
            <select id="retentionLevel" type="text" name="retentionLevel" class="layui-input" style="width: 8em;" lay-filter="retentionLevel">
                <option value="A">24h以上</option>
                <option value="B">72h以上</option>
            </select>
        </div>
        <div class="layui-inline">
            <!--          <input id="deptName" type="text" name="orderDept" class="layui-input" style="width: 8em;" placeholder="所属部门" value="" >-->
            <select id="process" type="text" name="process" class="layui-input" style="width: 8em;" lay-filter="process">
                <option value="">请选择工序站....</option>
            </select>
        </div>
        <div class="layui-inline">
            <input type="text" name="displayLength" class="layui-input" style="display: none;" placeholder="每页页数" value="15">
            <button id="searchBtn" type="submit" class="layui-btn" lay-submit="" lay-filter="searchBtn">查询工单滞留信息</button>
            <button type="button" class="layui-btn layui-bg-red" lay-submit="" lay-filter="exportBtn">导出报表</button>
        </div>

    </div>
</form>

<table class="layui-table" id="orderTable">
    <thead>
    <tr>
        <!--<th><input type="checkbox" id="select" onclick="selectAll()" /></th>-->
        <th style="text-align: center">工单编号</th>
        <th style="text-align: center">品名</th>
        <th style="text-align: center">父工单</th>
        <th style="text-align: center">当前站台</th>
        <th style="text-align: center">入站时间</th>
        <th style="text-align: center">已滞留时长
        <span class="layui-table-sort layui-inline">
              <i class="layui-edge layui-table-sort-asc" title="从低到高排序" onclick="sortRetentionTime('asc')"></i>
              <i class="layui-edge layui-table-sort-desc" title="从高到低排序" onclick="sortRetentionTime('desc')"></i>
            </span>
    </th>
    </tr>
    </thead>
    <tbody></tbody>
</table>
<div style="display: flex;">
    <div style="flex: 1">
        <div class="pageNav">
          <span class="layui-breadcrumb" lay-separator="-">
            <a class="fristPage">首页</a>
            <a class="lastPage">上一页</a>
            <a><cite>第<span id="page"></span>页</cite></a>
            <a class="nextPage">下一页</a>
            <a class="endPage">尾页</a>
          </span>
        </div>
    </div>
</div>

<div id="viewDiv"  class="site-text" style="margin: 5%; display: none"></div>
<div id="checkBox"  class="site-text" style="margin: 5%; display: none"></div>
<div id="viewWorker"  class="site-text" style="margin: 5%; display: none"></div>
<div id="processPdf"  class="site-text" style="margin: 5%; display: none"></div>

<script type="text/javascript">
    var displayStart = 1;
    var endPage = null;
    var layer = layui.layer;
    var laydate = null;
    var form = null;
    var list = null;

    layui.use(['form', 'element', 'laydate'], function() {
        form = layui.form;
        laydate = layui.laydate;
        $.ajax({
            url: url + '/sys-dept/listDept',
            method: 'POST',
            async : false,
            contentType: 'application/json',
            success: function(res) {
                //显示前先判断是否为管理员
                $.ajax({
                    url: '/sys-user/getAdmin/'+sessionStorage.getItem('userId'),
                    method: 'GET',
                    async : false,
                    contentType: 'application/json',
                    success: function (res) {
                        if (res.code===200){
                            isAd=1;
                        }
                        else if (res.code===400){
                            isAd=0;
                            thisDept=res.data.dept;
                        }
                    }
                })
                //按照是否为管理员显示下拉框
                if (res.code == 200) {
                    for (var i = 0; i < res.data.length; i++) {
                        if(isAd===1){
                            $("#deptName").append("<option value='" + res.data[i].id + "'>" + res.data[i].dept +"</option>");
                        }else if (isAd===0&&res.data[i].dept===thisDept){
                            $("#deptName").append("<option selected='selected' value='" + res.data[i].id + "'>" + res.data[i].dept +"</option>").attr('disabled','disabled');
                        }
                    }
                    form.render('select');
                }
            }
        })
        //工序下拉框
        $.ajax({
            url: url + '/process-info/listProcess',
            method: 'POST',
            async : false,
            contentType: 'application/json',
            data: JSON.stringify({
                deptId: $("#deptName").val()
            }),
            success: function(res) {
                if (res.code == 200) {
                    for (var i = 0; i < res.data.length; i++) {
                        $("#process").append("<option value='" + res.data[i].id + "'>" + res.data[i].processName +
                            "</option>");
                    }
                    form.render('select');
                }
            }
        })
        //下拉框二级联动---点击部门下拉框
        form.on('select(orderDept)', function(data) {
            $("#process").empty()
            //工序下拉框
            $.ajax({
                url: url + '/process-info/listProcess',
                method: 'POST',
                async : false,
                contentType: 'application/json',
                data: JSON.stringify({
                    deptId: $("#deptName").val()
                }),
                success: function(res) {
                    $("#process").append("<option value=''>请选择工序站....</option>");
                    if (res.code == 200) {
                        for (var i = 0; i < res.data.length; i++) {
                            $("#process").append("<option value='" + res.data[i].id + "'>" + res.data[i].processName +
                                "</option>");
                        }
                        form.render('select');
                    }
                }
            })
            form.render('select');
        });

        search(1);


        form.on('submit(searchBtn)', function() {
            search(1);
            return false;
        });
        $('.fristPage').click(function() {
            search(1);
            return false;
        });
        $('.lastPage').click(function() {
            search((displayStart > 1 ? displayStart - 1 : 1));
            return false;
        });
        $('.nextPage').click(function() {
            search((displayStart < endPage ? displayStart + 1 : endPage));
            return false;
        });
        $('.endPage').click(function() {
            search(endPage);
            return false;
        });
        //导出
        form.on('submit(exportBtn)', function() {
            var data = [];
            //数据定格
            data[0]=sessionStorage.getItem('loginName');
            data[1]=$('#orderNum').val();//orderNum
            data[2]=$('#process').val();
            data[3]=$('#deptName').val();
            data[4]=$('#retentionLevel').val();
            console.log(data)
            let confirm1=layer.confirm('按照所选条件导出结果报表？', {
                    btn: ['确认','取消']
                },function () {
                    layer.open({
                        type: 2,
                        title: '下载提示框',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['300px', '300px'],
                        content: url+'/excel/exportRetentionInfo/'+data
                    });
                    layer.close(confirm1);
                    layer.alert('正在导出..请选择允许下载多项！！！导出后在下载记录里可以找到!', {
                        icon: 1,
                        skin: 'layer-ext-demo', //见：扩展说明
                        end: function () {
                            //关闭弹出
                            layer.closeAll('iframe');
                            search(1)
                        }
                    })
                }
                ,function (){
                    layer.close(confirm1);
                }
            )
        });
    })

    function sortRetentionTime(date) {
        var index = layer.load(2, {
            shade: [0.5,'#fff'] //0.1透明度的白色背景
        });
        setTimeout(function() {
            layer.close(index)
        }, 300);
        search(1,date)
    }

    function isAdminOfProcess() {
        $.ajax({
            url: '/sys-user/getAdmin/'+sessionStorage.getItem('userId'),
            method: 'GET',
            contentType: 'application/json',
            success: function (res) {
                if (res.code===200){
                }
                else if (res.code===400){
                    $('#deptName').attr('disabled','disabled');
                    layer.msg("非管理员只能查看本部门滞留单");
                }
            }
        })
    }

    function search(index,sort) {
        if (!index) var index = displayStart;
        var data = form.val('data');
        data.displayStart = index;
        data.userId=sessionStorage.getItem('userId');
        data.sortStatus=sort;
        $.ajax({
            url: url + '/work-order/retentionOrder',
            method: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function(res) {
                $('tbody').empty();
                displayStart = res.data.current;
                endPage = res.data.pages;
                list = res.data.records;
                var resultList= res.data.records.filter(n => n);
                for (var i = 0; i < resultList.length; i++) {
                    if(resultList[i]!=null){
                        $('tbody').append(
                            "<tr>" +
                            "<td style='color:#1E9FFF;'>" + resultList[i].orderNum + "</td>" +
                            "<td style='color:#1E9FFF;'>" + resultList[i].pinName+ "</td>" +
                            "<td>" + resultList[i].lotNo+ "</td>" +
                            "<td>" + resultList[i].nowProcess + "</td>" +
                            "<td style='color:#1E9FFF;'>" + resultList[i].createNow.replace('T',' ') + "</td>" +
                            "<td style='color:#FF5722;'>" + resultList[i].retentionTime + "</td>" +
                            "</tr>"
                        );
                    }
                }
                $('#page').html(displayStart)
            }
        })
    }
</script>
</body>
</html>